clear
set mem 10000000
use "~/PSRM_REP_DATA_HUBER_TUCKER.dta"



***Figure 1A
mean scale_state if pid7>=1 & pid7<=3
mean scale_state if pid7>=5 & pid7<=7
mean scale_state if biden_state==0
mean scale_state if biden_state==1
mean scale_state if pid7>=1 & pid7<=3 & biden_state==1
mean scale_state if pid7>=5 & pid7<=7 & biden_state==1
mean scale_state if pid7>=1 & pid7<=3 & biden_state==0
mean scale_state if pid7>=5 & pid7<=7 & biden_state==0

***Figure 1B
mean scale_biden if pid7>=1 & pid7<=3
mean scale_biden if pid7>=5 & pid7<=7
mean scale_biden if biden_state==0
mean scale_biden if biden_state==1
mean scale_biden if pid7>=1 & pid7<=3 & biden_state==1
mean scale_biden if pid7>=5 & pid7<=7 & biden_state==1
mean scale_biden if pid7>=1 & pid7<=3 & biden_state==0
mean scale_biden if pid7>=5 & pid7<=7 & biden_state==0
***Figure 1C 
mean pop_biden_scale if pid7>=1 & pid7<=3
mean pop_biden_scale if pid7>=5 & pid7<=7
mean pop_biden_scale if biden_state==0
mean pop_biden_scale if biden_state==1
mean pop_biden_scale if pid7>=1 & pid7<=3 & biden_state==1
mean pop_biden_scale if pid7>=5 & pid7<=7 & biden_state==1
mean pop_biden_scale if pid7>=1 & pid7<=3 & biden_state==0
mean pop_biden_scale if pid7>=5 & pid7<=7 & biden_state==0

gen Biden_ec=.
replace Biden_ec=0 if YAL327==1 | YAL327==2
replace Biden_ec=1 if YAL327==4 | YAL327==5

gen Biden_ec_dk=.
replace Biden_ec_dk =0 if YAL327==1 | YAL327==2 | YAL327==4 | YAL327==5
replace Biden_ec_dk =1 if YAL327==3

gen Biden_pv=.
replace Biden_pv=0 if YAL328==1 | YAL328==2
replace Biden_pv=1 if YAL328==4 | YAL328==5

gen Biden_pv_dk=.
replace Biden_pv_dk =0 if YAL328==1 | YAL328==2 | YAL328==4 | YAL328==5
replace Biden_pv_dk =1 if YAL328==3

****Tossup states
gen tossupstate=0 
replace tossupstate=1 if state_fixed>=24 & state_fixed<=31

ttest scale_state, by (biden_state)



***Figure 2, Panel A Table A1
reg biden_binary i.state_fixed 
outreg using "~/TableA1.doc", replace ctitle(Coefficients)
***Figure 2, Panel B Table A2
reg state_dk i.state_fixed 
outreg using "~/TableA2.doc", replace ctitle(Coefficients)
**Table A3
logit biden_binary i.state_fixed 
outreg using "~/TableA3.doc", replace ctitle(Coefficients)
**Table A4
logit state_dk i.state_fixed 
outreg using "~/TableA4.doc", replace ctitle(Coefficients)
***Figure A1
reg Biden_ec i.state_fixed 
reg Biden_ec_dk i.state_fixed 

***Figure A2
reg Biden_pv i.state_fixed 
reg Biden_pv_dk i.state_fixed 

***Figure A3
reg YAL329 i.state_fixed
***Figure A4
reg biden_binary i.state_fixed i.pid7 educ age i.gender i.white i.urban income 
reg state_dk i.state_fixed i.pid7 educ age i.gender i.white i.urban income 

***Figure A5
reg biden_binary i.state_fixed i.pid7 educ age i.gender i.white i.urban income [pw= teamweight]
reg state_dk i.state_fixed i.pid7 educ age i.gender i.white i.urban income  [pw= teamweight]

****Knowledge question
gen state_house_rep=0
replace state_house_rep=1 if state_fixed==1 | state_fixed==2 | state_fixed==3 | state_fixed==4 | state_fixed==5 | state_fixed==6 | state_fixed==7 | state_fixed==8 | state_fixed==9 | state_fixed==10 | state_fixed==11 | state_fixed==13 | state_fixed==14 | state_fixed==15 | state_fixed==16 | state_fixed==17 | state_fixed==18 | state_fixed==19 | state_fixed==21 | state_fixed==22 | state_fixed==23 | state_fixed==24 | state_fixed==25 | state_fixed==26 | state_fixed==27 | state_fixed==28 | state_fixed==29 | state_fixed==31

gen state_house_dem=0
replace state_house_dem=1 if state_house_rep==0
replace state_house_dem=0 if state_fixed ==20 | state_fixed ==12


gen state_senate_rep=0
replace state_senate_rep=1 if state_fixed==1 | state_fixed==2 | state_fixed==3 | state_fixed==4 | state_fixed==5 | state_fixed==6 | state_fixed==7 | state_fixed==8 | state_fixed==9 | state_fixed==10 | state_fixed==11 | state_fixed==13 | state_fixed==14 | state_fixed==15 | state_fixed==16 | state_fixed==17 | state_fixed==18 | state_fixed==19 | state_fixed==21 | state_fixed==22 | state_fixed==23 | state_fixed==24 | state_fixed==25 | state_fixed==26 | state_fixed==27 | state_fixed==28 | state_fixed==29 | state_fixed==31 | state_fixed==32

gen state_senate_dem=0 
replace state_senate_dem=1 if state_senate_rep==0
replace state_senate_dem=0 if state_fixed ==12


gen right_state_house=0
replace right_state_house=1 if CC20_310d==1 & state_house_rep==1
replace right_state_house=1 if CC20_310d==2 & state_house_dem==1
replace right_state_house=1 if CC20_310d==3 & (state_fixed ==20 | state_fixed ==12)

gen right_state_senate=0
replace right_state_senate =1 if CC20_310c==1 & state_house_rep==1
replace right_state_senate =1 if CC20_310c==2 & state_house_dem==1
replace right_state_senate =1 if CC20_310c==3 & (state_fixed ==12)

gen right_us_house=0
replace right_us_house=1 if CC20_310a==2

gen right_us_senate=0
replace right_us_senate =1 if CC20_310b==1


gen total_right= right_state_house+ right_state_senate+ right_us_house+ right_us_senate


***Figure A6
reg biden_binary i.state_fixed if  total_right==4
reg biden_binary i.state_fixed if  total_right<4


***Figure A7
**Dems
reg biden_binary i.state_fixed if pid7>=1 & pid7<=3
**Reps
reg biden_binary i.state_fixed if pid7>=5 & pid7<=7


***Figure A8. A
mean scale_state if pid7>=1 & pid7<=3 & tossupstate==1
mean scale_state if pid7>=5 & pid7<=7 & tossupstate==1
mean scale_state if biden_state==0 & tossupstate==1
mean scale_state if biden_state==1 & tossupstate==1
mean scale_state if pid7>=1 & pid7<=3 & biden_state==1 & tossupstate==1
mean scale_state if pid7>=5 & pid7<=7 & biden_state==1 & tossupstate==1
mean scale_state if pid7>=1 & pid7<=3 & biden_state==0 & tossupstate==1
mean scale_state if pid7>=5 & pid7<=7 & biden_state==0 & tossupstate==1

***Figure A8. B
mean scale_biden if pid7>=1 & pid7<=3 & tossupstate==1
mean scale_biden if pid7>=5 & pid7<=7 & tossupstate==1
mean scale_biden if biden_state==0 & tossupstate==1
mean scale_biden if biden_state==1 & tossupstate==1
mean scale_biden if pid7>=1 & pid7<=3 & biden_state==1 & tossupstate==1
mean scale_biden if pid7>=5 & pid7<=7 & biden_state==1 & tossupstate==1
mean scale_biden if pid7>=1 & pid7<=3 & biden_state==0 & tossupstate==1
mean scale_biden if pid7>=5 & pid7<=7 & biden_state==0 & tossupstate==1
***Figure A8 C 
mean pop_biden_scale if pid7>=1 & pid7<=3 & tossupstate==1
mean pop_biden_scale if pid7>=5 & pid7<=7 & tossupstate==1
mean pop_biden_scale if biden_state==0 & tossupstate==1
mean pop_biden_scale if biden_state==1 & tossupstate==1
mean pop_biden_scale if pid7>=1 & pid7<=3 & biden_state==1 & tossupstate==1
mean pop_biden_scale if pid7>=5 & pid7<=7 & biden_state==1 & tossupstate==1
mean pop_biden_scale if pid7>=1 & pid7<=3 & biden_state==0 & tossupstate==1
mean pop_biden_scale if pid7>=5 & pid7<=7 & biden_state==0 & tossupstate==1
